var mask = null;
var login_user = null
var todo = null
var arry  = []
$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	datetime_init();
	mui.init();


	setTimeout(function() {
		//loadSchoolStatistics()
	}, 500);
	login_user = JSON.parse(localStorage.getItem('loginUser'));

	todo = JSON.parse(sessionStorage.getItem('todo'));
	pushData()
	app.todos = arry
})


function loadSchoolStatistics() {

	var data = {};
	data['schoolid'] = schoolid
	data['startdate'] = startCurrentMonth()
	data['enddate'] = startCurrentMonth()
	console.log("=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "newstatic/fx_jdl",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 100000,
		beforeSend: function() {
			mask.show(); //显示遮罩层	
		},
		success: function(res) {


			mask.close(); //显示遮罩层 	  
			console.log("记录列表=====" + JSON.stringify(res));

			loadApp(res);

		},
		error: function(e) {
			console.log("错误信息====" + JSON.stringify(e));
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("错误信息====" + JSON.stringify(e));
		}
	});


}


var app = new Vue({
	el: '#app',
	data: {
		show: true,
		todos: []
	},
	methods: {
		selected: function(todo) {
			console.log("todo==="+JSON.stringify(todo))
			
		}
	}
});

function loadApp(data) {
	var num = data.length - 1
	console.log("data====" + JSON.stringify(data));

	for (var i = 0; i < data.length; i++) {
		var d = data[i];
		var o = new Object();
		for (var x in d) {
			o[x] = d[x];
		}
		if(i == num){
			o['校区名称'] = "合计"
		}
		app.todos.push(o);
	}
}


function startCurrentMonth() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var startTime = year + "-";
	if (month < 10)
		startTime += "0";
	startTime += month
	return (startTime);
}


function pushData(){
		
		for(var key in todo){
			var obj = new Object()
			// console.log("key====="+key)
			// console.log("value====="+todo[key])
			if(key != "校区ID" && key != "排名"){
				obj["key"] = key
				obj["value"] = todo[key]
				arry.push(obj)
			}
			
		}
	console.log("arry======"+JSON.stringify(arry))
	
}